package basic.socket.upload;

import java.io.*;
import java.net.Socket;

/**
 * @author bingo
 * @Description
 * @Date 2018/7/24
 */
public class Client {

    public static void main(String[] args) {
        try {
            Socket socket = new Socket("localhost",8888);
            FileInputStream fis = new FileInputStream(new File("demo/cnaidc.png"));
            FileOutputStream fos = (FileOutputStream) socket.getOutputStream();
            FileInputStream socketInptStream = (FileInputStream) socket.getInputStream();
            byte[] bytes = new byte[1024];
            int len = 0;
            while ((len = fis.read(bytes))!=-1){
                fos.write(bytes);
                fos.flush();
            }
            socket.shutdownOutput();

            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socketInptStream));
            System.out.println("收到了。。。");
            String info;
            String result = "";
            System.out.println("阻塞了。。。。。");
            System.out.println(bufferedReader.readLine());
            System.out.println(result);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
